<%--***************************************
*
*银联
*
***************************************--%>
<%@ page import="
	java.util.*,
	java.text.*,
	java.math.*,
	chinapay.*,
	org.apache.commons.lang.StringUtils,
	com.probiz.estore.common.util.DateUtil,
	com.probiz.estore.common.model.order.SalesOrder,
	com.probiz.estore.common.model.system.PaymentGateway,
	com.probiz.estore.common.helper.ConfigUtil"
	contentType="text/html; charset=UTF-8"%>
 <%
 		SalesOrder salesOrder = (SalesOrder) request.getAttribute("salesOrder");
		PaymentGateway paymentGateway = (PaymentGateway) request.getAttribute("paymentGateway");
		request.setAttribute("paymentGateway",paymentGateway);
		HashMap paramMap = paymentGateway.getConfigData();

		//-----------------------start: 账户信息------------------------------------------
		String merId="";
		String merPrk="";
		String type="";
		if (paramMap != null) {
			merId = paramMap.get("merId").toString().trim(); 					//商户号
			merPrk = paramMap.get("merPrk").toString().trim(); 					//商户签名私钥
			type = paramMap.get("type").toString().trim(); 						//接入模式
		}
		//-----------------------end:   账户信息------------------------------------------

		//-----------------------start: 配置信息------------------------------------------
		String pageRetUrl = ConfigUtil.getInstance().getStoreFrontSiteUrl()+"/system/payment/chinapay_response_notify.html"; 	//页面交易接收URL
		String bgRetUrl = ConfigUtil.getInstance().getStoreFrontSiteUrl()+ "/system/payment/chinapay_response.html"; 			//后台交易接收URL
		String serverUrl="";		//提交地址
		if(type.equals("1")){
			serverUrl="https://payment.chinapay.com/pay/TransGet";
		}else{
			serverUrl="http://payment-test.chinapay.com/pay/TransGet";
		}
		//-----------------------end:   配置信息------------------------------------------

		//-----------------------start: 业务信息------------------------------------------
 		String orderNo = salesOrder.getOrderNo();
		String curyId = "156";				//订单交易币种，3位长度，固定为人民币156  必填
		String transType = "0001";			//交易类型：0001为消费交易
		String version = "20070129";		//支付接入版本号，必填
		DecimalFormat df=new DecimalFormat("0.00");

		String transDate = DateUtil.convertDateToString(new Date(),"yyyyMMdd"); //订单交易日期，8位长度，必填
		String amountStr =  StringUtils.leftPad(salesOrder.getUnPaidAmount().multiply(new BigDecimal("100")).intValue()+"", 12,"0"); //订单交易金额，12位长度，左补0，必填,单位为分
		StringBuffer chkValueStr = new StringBuffer();
		chkValueStr.append(merId).append(orderNo).append(amountStr).append(curyId).append(transDate).append(transType);
		String chkValue = "";
		PrivateKey key = new PrivateKey();
		SecureLink t ;
		try{
			key.buildKey(merId, 0, merPrk);
			t = new SecureLink(key);
			chkValue = t.Sign(chkValueStr.toString());
		}catch (Exception e) {
			e.printStackTrace();
		}
		//-----------------------end: 	业务信息------------------------------------------


 %>
 <div style="display:none">
	<form action="<%=serverUrl%>" method="post"  name="paymentGatewayForm">
		<input type=hidden name="MerId" value="<%=merId %>"/>
		<input type=hidden name="OrdId" value="<%=orderNo%>"/>
		<input type=hidden name="TransAmt" value="<%=amountStr%>"/>
		<input type=hidden name="CuryId" value="<%=curyId%>"/>
		<input type=hidden name="TransDate" value="<%=transDate%>"/>
		<input type=hidden name="TransType" value="<%=transType%>"/>
		<input type=hidden name="Version" value="<%=version%>"/>
		<input type=hidden name="BgRetUrl" value="<%=bgRetUrl%>"/>
		<input type=hidden name="PageRetUrl" value="<%=pageRetUrl%>"/>
		<input type=hidden name="GateId" value="">
		<input type=hidden name="Priv1" value="<%=orderNo%>">
		<input type=hidden name="ChkValue" value="<%=chkValue%>">
	</form>
 </div>

<script type="text/javascript">
$j(document).ready(function () {
	document.forms["paymentGatewayForm"].submit();
});
</script>

<%@ include file="./include/payOrderTips.jspf" %>